package com.pharmacy.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.pharmacy.dto.CategoriesPageSelectDto;
import com.pharmacy.entity.ExpiredDrugs;
import com.pharmacy.mapper.ExpiredDrugsMapper;
import com.pharmacy.result.PageResult;
import com.pharmacy.service.ExpiredDrugsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class ExpiredDrugsServiceImpl implements ExpiredDrugsService {


    @Autowired
    private ExpiredDrugsMapper expiredDrugsMapper;


    /**
     * 分页查询过期药品
     */
    @Override
    public PageResult pageSelect(CategoriesPageSelectDto categoriesPageSelectDto) {

        PageHelper.startPage(categoriesPageSelectDto.getPage(),categoriesPageSelectDto.getPageSize());
        Page<ExpiredDrugs> page = expiredDrugsMapper.pageSelect(categoriesPageSelectDto);
        long total = page.getTotal();
        List<ExpiredDrugs> records = page.getResult();

        return new PageResult(total,records);
    }

    /**
     * 删除过期药品
     */
    @Override
    public void deleteExpiredDrugs(Integer id) {
        expiredDrugsMapper.deleteExpiredDrugs(id);
    }
}
